package com.manli.api.service;

import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.List;
import com.manli.api.pojo.Result;
import com.manli.api.util.QueryParamsMapUtil;
import com.manli.api.util.ResultUtil;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import com.manli.api.dao.LoggingEventDao;
import com.manli.api.dto.LoggingEvent;


@Service("loggingEventService")
public class LoggingEventService {
    @Autowired
    LoggingEventDao loggingEventDao;

    
    public Result queryPage(Map<String, Object> params) {
        PageQuery<LoggingEvent> page = loggingEventDao.createQuery()
        		.appendSql(" where 1=1 ")
                .appendSql(QueryParamsMapUtil.paramIsEmpty(params.get("startTime"))?"":" and timestmp >= UNIX_TIMESTAMP('" + params.get("startTime")+"'"+")*1000 " )
                .appendSql(QueryParamsMapUtil.paramIsEmpty(params.get("endTime"))?"":" and timestmp <= UNIX_TIMESTAMP('" + params.get("endTime")+"'"+")*1000 " )
                .orderBy(" timestmp desc  ")
                .page(Long.parseLong(params.get("page").toString()),Long.parseLong(params.get("limit").toString())); 
        return ResultUtil.success(page.getList(),page.getTotalRow());
    }
}
